/**
 * 通用store
 */
import { makeAutoObservable } from "mobx";
import {
  FileAddOutlined,
  BgColorsOutlined,
  SettingOutlined,
  TableOutlined,
  UnorderedListOutlined,
  AppstoreOutlined,
  ExperimentOutlined,
  UserOutlined,
  ReadOutlined,
  TranslationOutlined,
  LoginOutlined,
} from "@ant-design/icons";

const MMPIX = "MMPIX";

interface ITMenu {
  // 图标
  readonly icon: any;

  // 值
  readonly value: string;

  // 语言key
  readonly langkey: string;
}

interface ITMenuChild extends ITMenu {
  // 路径
  readonly path?: string;
}

interface ITMenuParent extends ITMenu {
  // 是否有子菜单
  readonly hasSub: boolean;

  readonly path?: string;

  // 子菜单数据
  readonly children?: ITMenuChild[];
}

interface ITSideMenuChild extends ITMenu {
  readonly path: string;
}

interface ITSideMenu extends ITMenu {
  readonly children: ITSideMenuChild[];
}

export interface ITGlobalStore {
  // 顶部菜单数据
  readonly menu: ITMenuParent[];

  // 侧边栏菜单
  readonly sideMenu: ITSideMenu[];

  // 用户菜单
  readonly userMenu: ITMenuChild[];

  // 毫米与像素倍数
  mmPixRate: number;

  // 修改毫米与像素倍数
  changeMmPixRate: (data: number) => void;
}

class GlobalStore {
  constructor() {
    makeAutoObservable(
      this,
      {
        menu: false,
        sideMenu: false,
        userMenu: false,
      },
      { autoBind: true }
    );
  }

  // 顶部菜单
  menu: ITMenuParent[] = [
    {
      icon: <FileAddOutlined />,
      value: "designerlist",
      langkey: "langprotocoldesigner",
      hasSub: false,
      path: "/designer",
    },
    {
        icon: <BgColorsOutlined />,
        value: "userreagents",
        langkey: "languserreagentmanage",
        hasSub: false,
        path: "/userreagents",
      },
    {
      icon: <BgColorsOutlined />,
      value: "reagentmanagement",
      langkey: "langreagentmanage",
      path: "/reagents",
      hasSub: false,
    },
    {
      icon: <SettingOutlined />,
      value: "setting",
      langkey: "langsetting",
      hasSub: true,
      children: [
        {
          icon: <TableOutlined />,
          value: "workbenchs",
          langkey: "langworkbenchlist",
          path: "/setting/workbenchs",
        },
        {
          icon: <AppstoreOutlined />,
          value: "shelfs",
          langkey: "langshelflist",
          path: "/setting/shelfs",
        },
        {
          icon: <ExperimentOutlined />,
          value: "bottles",
          langkey: "langbottlelist",
          path: "/setting/bottles",
        },
        {
          icon: <BgColorsOutlined />,
          value: "reagents",
          langkey: "langreagentlist",
          path: "/setting/reagents",
        },
        {
          icon: <SettingOutlined />,
          value: "baseset",
          langkey: "langbase",
          path: "/setting/baseset",
        },
        {
          icon: <UserOutlined />,
          value: "user",
          langkey: "languser",
          path: "/setting/user",
        },
        {
          icon: <ReadOutlined />,
          value: "datadictionary",
          langkey: "langdatadictionary",
          path: "/setting/datadictionary",
        },
      ],
    },
  ];

  // 侧边栏菜单
  sideMenu: ITSideMenu[] = [
    {
      icon: <TableOutlined />,
      value: "workbench",
      langkey: "langworkbench",
      children: [
        {
          icon: <UnorderedListOutlined />,
          value: "workbenchs",
          langkey: "langworkbenchlist",
          path: "/setting/workbenchs",
        },
        {
          icon: <UnorderedListOutlined />,
          value: "experimenttable",
          langkey: "langexperimenttablelist",
          path: "/setting/experimenttable",
        },
      ],
    },
    {
      icon: <AppstoreOutlined />,
      value: "shelf",
      langkey: "langshelf",
      children: [
        {
          icon: <UnorderedListOutlined />,
          value: "shelfs",
          langkey: "langshelflist",
          path: "/setting/shelfs",
        },
      ],
    },
    {
      icon: <ExperimentOutlined />,
      value: "Bottle",
      langkey: "langbottle",
      children: [
        {
          icon: <UnorderedListOutlined />,
          value: "bottles",
          langkey: "langbottlelist",
          path: "/setting/bottles",
        },
      ],
    },
    {
      icon: <BgColorsOutlined />,
      value: "Reagent",
      langkey: "langreagent",
      children: [
        {
          icon: <UnorderedListOutlined />,
          value: "reagents",
          langkey: "langreagentlist",
          path: "/setting/reagents",
        },
      ],
    },
    {
      icon: <SettingOutlined />,
      value: "setting",
      langkey: "langsetting",
      children: [
        {
          icon: <UnorderedListOutlined />,
          value: "baseset",
          langkey: "langbase",
          path: "/setting/baseset",
        },
        {
          icon: <UserOutlined />,
          value: "user",
          langkey: "languser",
          path: "/setting/user",
        },
        {
          icon: <ReadOutlined />,
          value: "datadictionary",
          langkey: "langdatadictionary",
          path: "/setting/datadictionary",
        },
        {
          icon: <TranslationOutlined />,
          value: "language",
          langkey: "langlanguage",
          path: "/setting/language",
        },
      ],
    },
  ];

  // 用户菜单
  userMenu: ITMenuChild[] = [
    {
      icon: <SettingOutlined />,
      value: "usermodify",
      langkey: "langsetting",
      path: "/user",
    },
    {
      icon: <LoginOutlined />,
      value: "loginout",
      langkey: "langlogout",
    },
  ];

  // 毫米与像素倍数
  mmPixRate = Number(window.localStorage.getItem(MMPIX)) || 4;

  // 修改毫米与像素倍数
  changeMmPixRate = (data: number) => {
    this.mmPixRate = data;
    window.localStorage.setItem(MMPIX, String(data));
  };
}

const globalStore: ITGlobalStore = new GlobalStore();
export default globalStore;
